package com.example.repository;

import com.example.data.holidays.Holidays;
import com.example.data.holidays.HolidaysBO;
import com.example.data.holidays.HolidaysDO;
import com.example.data.holidays.HolidaysVO;
import com.example.mappers.HolidaysRowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;


import java.util.*;


@Repository
public class HolidaysRepository {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    //查询所有员工假期信息
    //todo
    public List<Holidays> getAllHolidaysInfo(){
        String sql = "SELECT * FROM holidays ORDER BY empId";
        List<Holidays> holidaysList = jdbcTemplate.query(sql, new HolidaysRowMapper());
        return holidaysList;
    }
    //查询某一员工假期信息
    //todo
    public Holidays getHolidaysInfoByID(long empID){ //change the return type to class
        String sql = "SELECT * FROM holidays WHERE empId=? ";
        Holidays holidays = jdbcTemplate.queryForObject(sql, new HolidaysRowMapper(), empID);
        return holidays;
    }



    public Holidays editRestHolidaysInfo(long id,Holidays holidays){//？BO
        String sql = "UPDATE holidays set availableHolidays=? , restHolidays =? WHERE empId=?";
        jdbcTemplate.update(sql,holidays.getAvailableHolidays(),holidays.getRestHolidays(),id);
        return (Holidays) queryHolidaysInfoByID(id);
    }
    //添加员工信息
    //todo
    public Holidays addHolidaysInfo(Holidays holidays){//?BO
        String sql = "INSERT INTO holidays (empId,availableHolidays,restHolidays) VALUES(?, ?, ?)";
        jdbcTemplate.update(sql, holidays.getEmpID(), holidays.getAvailableHolidays(),holidays.getRestHolidays());
        String sql2 = "SELECT * FROM holidays WHERE empId=? ";//这里没有类似学号的假期号不好返回
        Holidays holidays2 = jdbcTemplate.queryForObject(sql2, new HolidaysRowMapper(), holidays.getEmpID());//long 换成 int有可能吧
        return holidays2;
    }
    //删除某一员工信息
    public void deleteHolidaysInfo(long empID){
        String sql = "DELETE FROM holidays WHERE id=?";
        jdbcTemplate.update(sql, empID);
    }
    //查询某一员工信息以map返回
    //todo
    public Map<String, Object> queryHolidaysInfoByID(long empID){
        Map<String, Object> holidaysMap = new LinkedHashMap<>();
        holidaysMap.put("empID", 11L);
        holidaysMap.put("availableHolidays", 22);
        holidaysMap.put("restHolidays", 33);
        return holidaysMap;
    }
    public List<Holidays> getFakeDO(){
        Holidays holidaysInfo = new HolidaysDO();
        holidaysInfo.setEmpID(11L);
        holidaysInfo.setAvailableHolidays(22);
        holidaysInfo.setRestHolidays(33);
        return Arrays.asList(holidaysInfo);
    }


}
